<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_adhj_call_t {
        background-color: #254060;
        height: 444px;
        color: white;
        overflow: auto;
    }

    .pa_andon_call {
        margin-top: 2%;
        height: 60px;
        line-height: 60px;
        width: 70%;
        margin-left: 30%;
        text-align: center;
    }

    .pa_andon_call_new {
        margin-top: 2%;
        height: 60px;
        line-height: 60px;
        width: 70%;
        margin-left: 9%;
        text-align: center;
    }

    .pa_adhj_call_but {
        height: 58px;
        line-height: 58px;
        float: left;
        width: 150px;
        font-size: 25px;
        color: white;
        margin-left: 50px;
        text-align: center;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    .hide {
        display: none;
    }

    .c1 {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .5);
        z-index: 99;
        margin-top: 12%;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟久泰</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:25%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:15%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>安灯呼叫</p>
            </div>
        </div>
        <div id="shade">
            <div class="aui-flex-col aui-flex-center">
                <div class="aui-flex-item-12 pa_adhj_call_t">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <div class="aui-flex-col pa_andon_call" style="display: none;">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        开工工单：</div>
                                    <div class="aui-list-item-input"
                                        style="background-color: white;float: left;width: 300px;">
                                        <input type='search' readOnly='true' id="workOrderCode" class="aui-input"
                                            onclick="opencauseOfDeficiency(api.pageParam.workCenterCode);" />
                                    </div>
                                </div>
                            </div>

                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        异常类型：</div>
                                    <div class="aui-list-item-input" style="background-color: white;float: left;">
                                        <select id="exceptionType" onchange="onChange()" style="width: 300px;">
                                        </select>
                                    </div>
                                </div>
                            </div>

                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        异常内容：</div>
                                    <div class="aui-list-item-input" style="background-color: white;float: left;">
                                        <select id="exceptionContent" style="width: 300px;">
                                            <option value=''>--请选择--</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        是否停台：</div>
                                    <div class="aui-list-item-input" style="background-color: white;float: left;">
                                        <select id="isStop" style="width: 300px;">
                                            <option value="0">否</option>
                                            <option value="1">是</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="aui-flex-col pa_andon_call_new">
                                <div style="font-size: 25px;">
                                    是否需要工艺维修人员到现场：</div>
                                <div class="aui-list-item-input" style="background-color: white;">
                                    <select id="isNeed" style="width: 300px;">
                                        <option value="否">否</option>
                                        <option value="是">是</option>
                                    </select>
                                </div>
                            </div>
                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注：</div>
                                    <div class="aui-list-item-input"
                                        style="background-color: white;float: left;width: 300px;">
                                        <input type="text" id="remark" class="aui-input" onclick="getIdSelector();" />
                                    </div>
                                </div>
                            </div>

                            <div class="aui-flex-col pa_andon_call">
                                <div class="pa_adhj_call_but" style="background-color: #4B7902;" id="submitButton"
                                    onclick="save()">
                                    提交
                                </div>
                                <div class="pa_adhj_call_but" style="background-color: #D9001B;" onclick="cancle()">
                                    关闭
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div id="modal" class="c2 hide">
            <div class="aui-flex-col aui-flex-center">
                <div class="aui-flex-item-12 pa_adhj_call_t">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <!-- <p
                                style="margin-left: 10px;font-size: 1rem;font-weight: 500;color: white;text-align: center;">
                                输入账号密码</p> -->
                            <!-- <ul class="aui-list aui-form-list" style="margin-top: 1%;"> -->
                            <!-- <li class="aui-list-item" id="chkmrlQtyItem"> -->
                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        账&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp号：</div>
                                    <div class="aui-list-item-input" style="background-color: white;float: left;">
                                        <input type="text" style="width: 300px;" id="username" />
                                    </div>
                                </div>
                            </div>

                            <div class="aui-flex-col pa_andon_call">
                                <div class="aui-list-item-inner" style="border: 0;">
                                    <div class="aui-list-item-label" style="font-size: 25px;float: left;">
                                        密&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp码：</div>
                                    <div class="aui-list-item-input" style="background-color: white;float: left;">
                                        <input type="password" style="width: 300px;" id="password" />
                                    </div>
                                </div>
                            </div>

                            <div class="aui-flex-col pa_andon_call">
                                <div class="pa_adhj_call_but" style="background-color: #4B7902;" id="submitButton"
                                    onclick="deal()">确定
                                </div>
                                <div class="pa_adhj_call_but" style="background-color: #D9001B;" onclick="Hide()">取消
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    //光标所在id
    var idSelector = "";
    var exceptionTypeId = "";
    var exceptionContentId = "";
    var workOrderCode = "";
    var workCenterCode = "";
    var isStop = "";
    var remark = "";
    var groupLeader = "";
    var shiftName = "";
    var shiftCode = "";
    var teamCode = "";
    var isNeed = "";

    //初始化
    apiready = function () {
        //获取班长
        groupLeader = api.pageParam.groupLeader;
        //班次名称
        shiftName = api.pageParam.shiftName;
        //班组编码
        teamCode = api.pageParam.teamCode;
        //班次编码
        shiftCode = api.pageParam.shiftCode;
        console.log(shiftName)
        console.log(groupLeader)
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //查询异常类型下拉框
        doSearchExceptionType();

    }
    function Show() {
        document.getElementById('modal').classList.remove('hide');
        document.getElementById('shade').classList.add('hide');
        document.getElementById('username').value = "";
        document.getElementById('password').value = "";
    }

    function Hide() {
        document.getElementById('modal').classList.add('hide');
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('username').value = "";
        document.getElementById('password').value = "";
    }

    //保存按钮
    function deal() {
        //账号
        var username = document.getElementById('username').value;
        //密码
        var password = document.getElementById('password').value;

        if (username == null || username == "" || username == undefined) {
            api.toast({
                msg: '账号不能为空！',
                duration: 3000
            });
            return;
        }
        if (password == null || password == "" || password == undefined) {
            api.toast({
                msg: '密码不能为空！',
                duration: 3000
            });
            return;
        }

        if (groupLeader == null || groupLeader == "" || groupLeader == undefined) {
            api.toast({
                msg: '班组长未维护！',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        // var url = serverUrl + "/app/qcmChkRecordSave";
        var url = serverUrl + "/app/CheckShiftUserAndPass";
        var data = {
            values: {
                groupLeader: groupLeader,
                _u: username,
                _p: password,
                un: un,
                teamCode: teamCode
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {
                    Hide();
                    submit()
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    // Hide();
                }
            } else {
                api.hideProgress();
            }
        });
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询异常类型下拉框
    function doSearchExceptionType() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_type",
                column_name: "name",
                column_value: "sysid",
                condition: "is_delete=0",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionType"), html);
                } else {
                    $api.html($api.byId("exceptionType"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //异常类型值改变
    function onChange() {
        var exceptionTypeId = $("#exceptionType").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_content",
                column_name: "name",
                column_value: "sysid",
                condition: "exception_type_gid= '" + exceptionTypeId + "'",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionContent"), html);
                } else {
                    $api.html($api.byId("exceptionContent"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //呼叫保存
    function save() {

        if (!clickThrottle()) {
            return;
        }

        exceptionTypeId = $("#exceptionType").val();
        exceptionContentId = $("#exceptionContent").val();
        workOrderCode = $("#workOrderCode").val();
        isStop = $("#isStop").val();
        remark = $("#remark").val();
        isNeed = $("#isNeed").val();

        if (exceptionTypeId == null || exceptionTypeId == "" || exceptionTypeId == undefined) {
            api.toast({
                msg: '请选择异常类型！',
                duration: 3000
            });
            return;
        }

        if (exceptionContentId == null || exceptionContentId == "" || exceptionContentId == undefined) {
            api.toast({
                msg: '请选择异常内容！',
                duration: 3000
            });
            return;
        }

        if (isStop == null || isStop == "" || isStop == undefined) {
            api.toast({
                msg: '请选择是否停台！',
                duration: 3000
            });
            return;
        }
        //输入账号密码弹框显示
        Show()
    }

    function submit() {
        const submitButton = document.getElementById('submitButton');
        submitButton.style.pointerEvents = "none"; // 禁用提交按钮
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonCall";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                //班次名称
                shiftName: api.pageParam.shiftName,
                //班次编码
                shiftCode: api.pageParam.shiftCode,
                exceptionTypeId: exceptionTypeId,
                exceptionContentId: exceptionContentId,
                workOrderCode: workOrderCode,
                isStop: isStop,
                remark: remark,
                isNeed: isNeed,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    cancle();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                submitButton.style.pointerEvents = "auto"; // 启用提交按钮
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //取消按钮
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'productionAssemblyAndon',
            script: 'refresh()'
        });
    }
    function opencauseOfDeficiency(workCen) {
        console.log(workCen)
        var pageParam = api.pageParam;
        pageParam.name = "productionAssemblyAndon_call";
        pageParam.workCen = workCen;
        api.openWin({
            name: "startWorkOrder",
            url: 'startWorkOrder.html',
            pageParam: pageParam,
        });
    }
    function setScrapName(workOrderCode) {
        if (workOrderCode != undefined) {
            $("#workOrderCode").val(workOrderCode)
        }

    }
    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>